<template>
	<view class="input-numCheck">
		<view class="scan-head">
			<view class="input-content">
				<uni-forms-item label="输入资产编码:">
					<uni-easyinput errorMessage v-model="assetNo" focus placeholder="请输入编号" suffixIcon="search"
						@iconClick="getAssetDetail">
					</uni-easyinput>
				</uni-forms-item>

				<view class="assetInfo">
					<view>资产名称：{{detailData.assetName?detailData.assetName:'未知'}}</view>
					<view>资产编号：{{detailData.assetNo?detailData.assetNo:'未知'}}</view>
					<view>资产状态：{{detailData.statusCh?detailData.statusCh:'未知'}}</view>
					<view>资产位置：{{detailData.storageLocationName?detailData.storageLocationName:'未知'}}</view>
				</view>

				<button type="primary" @click="submit" class="start-button">
					<uni-icons type="compose" size="20" color="#fff"></uni-icons>&nbsp;确认签收
				</button>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import {
		ref
	} from 'vue'
	import {
		assetDetail,
		qrSign
	} from "@/common/api/assetAPI.ts";
	import {
		onLoad
	} from "@dcloudio/uni-app";

	let assetNo = ref('')
	let detailData = ref({})

	onLoad((par) => {
		if (par.qrCode) {
			assetNo.value = par.qrCode
			getAssetDetail(par.qrCode)
		} else {
			uni.showToast({
				icon:'none',
				title:'二维码扫描失败，请手动输入编号！'
			})
		}
	})

	function getAssetDetail(qrCode) {
		assetDetail(qrCode).then((value) => {
			if (value.code == 0) {
				detailData.value = value.data;
			} else {
				uni.showToast({
					icon:'none',
					title:'数据获取失败!'
				})
			}
		});
	}

	const submit = () => {
		qrSign([assetNo.value]).then(value => {
			if (value.code == 0) {
				uni.showToast({
					icon:'none',
					title:'提交成功！',
					duration:500
				})
				setTimeout(()=>{
					uni.navigateBack({
						delta: 1
					});
				},500)
				
			} else {
				uni.showToast({
					icon:'none',
					title:value.message
				})
			}
		})
	}
</script>

<style lang="scss" scoped>
	uni-page-body {
		height: 100%;
	}

	.assetInfo>view {
		border-bottom: 1px solid #999;
		font-size: 16px;
		padding: 15px;
	}

	.input-numCheck {
		width: 100%;
		height: 100%;

		.scan-head {
			padding-top: 30rpx;
			height: 400rpx;
			background: url(../../../src/static/img/bg1.png) no-repeat;
			background-size: 100% 100%;
			box-sizing: border-box;
		}

		.card-title {
			padding: 10px;
			border-bottom: 1px solid #ebeef5;

		}

		.input-content {
			background-color: #fff;
			width: 90vw;
			margin-left: 5vw;
			border-radius: 10rpx;
			box-shadow: (0, 0, 0, 0.08) 0px 0px 3px 1px;
			padding: 30rpx 20rpx 30rpx 20rpx;
			box-sizing: border-box;

			:deep(.uni-forms-item__label) {
				width: 95px !important;
			}

			.start-button {
				margin: 80rpx 0;
				background-color: #198a6c;
				line-height: 2;
			}
		}
	}
</style>
